/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  NativeModules,
  Platform,
  PermissionsAndroid
} from 'react-native';


import AppStorage from './component/appstorage';

import Navigator from './component/navigator';

import Index from './pages/index';
import Toast from 'react-native-root-toast';
//import SplashScreen from 'react-native-splash-screen'

export default class App extends Component {
	componentWillMount(){
		if( Platform.OS === 'android'){
			this.timer=setTimeout(() => {
		  		NativeModules.SplashScreen.hide();
		  	},100)
	  	}
	  	this.askPermission();
		AppStorage.isLogin("login");
	}
	async askPermission() {  
		if(Platform.OS === 'android'){   
			try {    
				const granted_readStorage = await PermissionsAndroid.requestMultiple(
					[PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,PermissionsAndroid.PERMISSIONS.CAMERA]
				)   
			} catch(err) {
				Toast.show("出错了，请稍后重试", {     
					duration: Toast.durations.LONG,     
					position: Toast.positions.CENTER,     
					shadow: true,     animation: true,     
					hideOnPress: true,     
					delay: 0    
				});   
			}
		}
	}
	componentWillUnmount() {  
	  	this.timer && clearTimeout(this.timer);  
	} 
	render() {
		return (
		  <Navigator component = {Index} />
		);
	}
}